<template>
  <div>
    <div class="model-title-css">
      <div class="title">
        施工安全巡视记录
      </div>
    </div>
    <div class="background_wrap">
      <div class="operate_wrap flexDiv">
        <div class="flex-left">
          <el-button type="primary" size="small" v-permission="permission.add" class="add buildButtonStyle" round @click="add">
            <i class="iconfont icon-icon_add"></i>&nbsp;新增
          </el-button>
        </div>
        <div class="flex-right">
          <!-- <el-select
            style="margin: 0; margin-right: 15px; margin-left: 15px"
            class="select"
            size="small"
            v-model="search.companyId"
            v-on:change="getProjectByCompanyId()"
            value-key="id"
            placeholder="选择公司"
            clearable
          >
            <el-option
              v-for="item in companyTree"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select> -->

          <el-select style="margin: 0; margin-right: 15px" class="select" size="small" v-model="search.projectId" v-on:change="getSectionByProjectId()" value-key="id" filterable placeholder="选择项目" clearable>
            <el-option v-for="item in projectTree" :key="item.id" :label="item.name" :value="item.id">
            </el-option>
          </el-select>

          <el-select style="margin: 0; margin-right: 15px" class="select" size="small" @change="getList(true)" v-model="search.sectionId" placeholder="选择标段" clearable>
            <el-option v-for="item in sectionTree" :key="item.id" :label="item.name" :value="item.id">
            </el-option>
          </el-select>
          <el-date-picker style="margin-right: 10px;width: 350px" v-model="search.logDates" type="daterange" unlink-panels value-format="yyyy-MM-dd HH:ss:mm" range-separator="至" start-placeholder="日志日期起始" end-placeholder="日志日期截止">
          </el-date-picker>
          <el-input style="width: 150px;" size="small" v-model="search.logNumber" placeholder="编号" clearable @keyup.enter.native="keydown()"></el-input>
          <el-button class="search" size="small" @click="getList(true)">
            <i class="iconfont icon-sousuo"></i> 搜索
          </el-button>
        </div>
      </div>
      <div class="list_wrap">
        <el-table class="engineeringLog-table" :border="true" :row-class-name="tableRowStyleName" :cell-class-name="tableCellStyleName" :header-cell-class-name="tableHeaderCellStyleName" :stripe="true" ref="multipleTable" :data="list" tooltip-effect="dark" @cell-click="cellClick" style="width: 100%; font-family: PingFangSC-Regular; font-size: 14px;" @selection-change="handleSelectionChange">
          <el-table-column show-overflow-tooltip label="序号" type="index" width="60">
            <template slot-scope="scope">
              <span>{{search.pageNo * search.pageSize + scope.$index + 1}}</span>
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip v-for="(item, i) in elTableList" :key="i" :sortable="item.sort ? item.sort : false" :min-width="item.width" :prop="item.prop" :formatter="formatter" :label="item.name">
          </el-table-column>
          <el-table-column label="文件预览" align="center" width="80">
            <template slot-scope="scope">
              <div class="table-iconfont-box row-i-hover-css">
                <i class="iconfont icon-a-wenjian1" v-if="scope.row.file&&scope.row.file.length>0" v-on:click="showFiles(scope.row,'施工安全巡视记录')"></i>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="创建时间" width="230">
            <template slot-scope="scope">
              <span>{{ scope.row.createTime }}</span>
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="13%" label="操作">
            <template slot-scope="scope">
              <el-button size="mini" v-permission="permission.show" class="menu_icon iconfont icon-icon_look action_color1" @click="showDialog('check','施工安全巡查记录查看',scope.row.id)">&nbsp;查看</el-button>
              <el-button size="mini" v-permission="permission.edit" class="menu_icon iconfont icon-xiugai-copy action_color1" @click="showDialog('edit','施工安全巡查记录编辑',scope.row.id)">&nbsp;修改</el-button>
              <el-button size="mini" v-permission="permission.del" class="menu_icon iconfont icon-shanchu action_color2" @click="showDialog('delete','施工安全巡查记录删除',scope.row.id)">&nbsp;删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination style="float: right; margin-top: 30px;" layout="prev, pager, next" :page-size="search.pageSize" :total="search.pageSum" :current-page="search.pageNo + 1" :prev-text="tablePaginationPrev" :next-text="tablePaginationNext" @current-change="paginationChange">
        </el-pagination>
      </div>
      <Detail :postDetail="postDetailData" @reloadList="getList(true)"></Detail>
      <el-dialog width="600px" class="approveDialog" :visible.sync="showFileDialog" :modal-append-to-body="false" :close-on-click-modal="false" append-to-body>
        <span slot="title">
          <i class="iconfont icon-a-wenjian1"></i>
          <span>附件</span>
        </span>
        <el-table v-loading="loading" element-loading-text="拼命加载中" element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.8)" :border="true" :header-cell-style="{padding: '0',height:'38px',backgroundColor: '#f2f2f2',textAlign:'center',borderColor: '#d4d4d4'}" :cell-style="{padding: '6px 0',textAlign:'center',borderColor: '#d4d4d4'}" ref="multipleTable" :data="nowFileList" style="width: 100%; font-family: PingFangSC-Regular; font-size: 14px;" @selection-change="handleSelectionChange">

          <el-table-column show-overflow-tooltip label="序号" type="index" width="60">

          </el-table-column>
          <el-table-column show-overflow-tooltip label="文件名" style="text-align: center" width="320">
            <template slot-scope="scope">
              <div style="text-align: center;" v-html="scope.row.fileName"></div>
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="20%" label="操作">
            <template slot-scope="scope">
              <el-tooltip class="item" effect="light" content="查看" placement="top">
                <div class="menu_icon" @click="viewFile(scope.row.id)" style="display: inline;cursor:pointer;margin-right: 5px"><i class='iconfont icon-icon_look'></i></div>
              </el-tooltip>
              <el-tooltip class="item" effect="light" content="下载" placement="top">
                <div class="menu_icon" @click="dlFile(scope.row)" style="display: inline;cursor:pointer"><i class='iconfont icon-icon-xiazai'></i></div>
              </el-tooltip>
            </template>
          </el-table-column>
        </el-table>

        <div slot="footer" class="dialog-footer">
          <!--新建和编辑的暂存上报-->
          <el-button size="small" @click="showFileDialog=false"><i class="iconfont icon-icon_cancel"></i> 关 闭
          </el-button>
        </div>
      </el-dialog>
    </div>
  </div>
</template>
<script>
import {
  tableRowStyleGol,
  tableCellStyleGol,
  tableHeaderCellStyleGol,
} from '@/utils/publicFun'
import projectSectionInfo from '@/api/buss/common'
import msgUtil from '@/utils/msgUtil'
import sgxslog from "@/api/buss/sgxslog"
import constrsafelog from "@/api/buss/constrsafelog";
import { Base64 } from 'js-base64'
import selectProjectAndSection from '@/mixins/selectProjectAndSection'
export default {
  name: "sgxslog-manage",
  mixins: [selectProjectAndSection],
  components: {
    Detail: require('./sgxslog-manage-detail/sgxslog-manage-detail').default,
  },
  data() {
    return {
      permission: {
        add: ['100', '1000100:add'],
        show: ['100', '1000100:show'],
        edit: ['100', '1000100:edit'],
        del: ['100', '1000100:del'],
      },
      tableRowStyleName: tableRowStyleGol,
      tableCellStyleName: tableCellStyleGol,
      tableHeaderCellStyleName: tableHeaderCellStyleGol,
      tablePaginationPrev: '上一页',
      tablePaginationNext: '下一页',
      companyTree: [], // 公司下拉
      projectTree: [], // 项目下拉
      sectionTree: [], // 标段下拉
      detailType: 'build', // 详情类型 build新建 check不可编辑查看 edit编辑
      file: [],
      needuploadfile: [],
      formlabelWidth: '100px', // 表单左侧标题宽度
      formBaseData: {

      }, // 表单基本信息内容
      search: {
        sortField: '',
        sortOrder: '',
        pageNo: 0,
        pageSize: 10,
        pageSum: 0,
        logDates: '',
        logNumber: '',
        companyId: '', //建设单位
        projectId: '', //项目名称
        sectionId: '',
      }, // 搜索参数

      allowSelContract: false,
      typeOptions: [{
        label: "施工单位",
        value: ""
      }],
      searchCode: [{
        label: "施工记录人",
        value: ""
      }],
      //  选项
      list: [], // 列表
      //  施工合同列表
      workContractList: [],
      contractNumber: '',//合同编号
      contractId: '',//合同id
      constrCompany: '',//施工单位
      constrCompanyName: '',//施工单位
      supervisorCompany: '',//监理单位
      supervisorCompanyName: '',//监理单位
      showFileDialog: false,
      fileTitle: '',
      nowFileList: [],
      logNumber: '',//日志编号
      logDate: '',//施工日志日期
      constrUser: '',//记录人
      projectName: '',//工程名称
      constrRemark: '',//备注
      loading: false,
      selectFile: '',
      fileOptions: [],
      showReportDialog: false,
      reportUrl: '',
      params: '',
      //  允许新增
      allowAdd: false,
      title: '',
      uuid: '',
      postDetailData: {
        show: false,
        type: 'build'
      }, // 向详情子组件的传值
      postHistoryData: {
        show: false,
      }, // 向子组件的传值
      fileSystem: {
        attachId: '',
        sys: 'buss',
        module: 'constrlog',
        part: ['one'],
      }, // 文件系统的参数

      measurePhaseNow: { status: 0, actions: {}, logList: [] },
      elTableList: [
        {
          name: '项目',
          prop: 'projectName',
          width: '10%',
        },
        {
          name: '标段',
          prop: 'sectionName',
          width: '10%',
        },
        {
          name: '编号',
          prop: 'logNumber',
          width: '10%',
        },
        {
          name: '记录日期',
          prop: 'logDate',
          width: '6%',
        },
        {
          name: '巡查员',
          prop: 'constrUser',
          width: '10%',
        },

      ], // el的table列表
    }
  },
  created() {
    this.initData()
  },
  methods: {
    keydown() {
      if (event.keyCode == 13) {
        this.getList(true)
      }
    },
    showDialog(type, typeNmae, detailId) {
      switch (type) {
        case 'build':
          this.postDetailData = {
            show: true,
            type: type,
            typeNmae: typeNmae,
            detailId: '',
          }
          break
        case 'edit':
        case 'check':
          this.postDetailData = {
            show: true,
            type: type,
            typeNmae: typeNmae,
            detailId: detailId,
          }
          break
        case 'delete':
          if (detailId === '') {
            msgUtil.error2('请先选择要删除的记录！')
            return
          }
          msgUtil.confirm('确认删除该条数据?').then(res => {
            let idlist = []
            idlist.push(detailId)
            let param = {
              ids: idlist
            }
            sgxslog.del(param).then(res => {
              if (res.code === 200) {
                msgUtil.success2('删除成功!')
                this.getList()
              } else {
                msgUtil.error2(res.data.message)
              }
            })
          })
          break
      }
    },
    initData() {
      this.companyTree = []
      projectSectionInfo.getProjSecTreeAll().then(res => {
        if (res.code === 200) {
          this.$set(this, 'projectTree', res.data)
          if (this.$headerSearch) {
            this.$set(this.search, 'projectId', this.changeHeaderProject)
            console.log(this.search, 66665554);
            this.projectTree.forEach((item) => {
              if (item.id === this.search.projectId) {
                this.sectionTree = item.children
              }
            })
            this.getSectionByProjectId()
          }
        } else {
          this.$messageError(res.data.message)
        }
      }).catch(() => {
        this.$messageError('获取项目标段树失败')
      })

    },
    add() {
      this.postDetailData = {
        show: true,
        type: 'build',
        typeName: '新增',
        detailId: '',
      }
    },
    /**
     *  根据建设单位查询下面的所有项目
     * */
    getProjectByCompanyId() {
      if (this.search.projectId) {
        this.search.projectId = ''
      }
      if (this.search.sectionId) {
        this.search.sectionId = ''
      }
      if (this.search.companyId != '') {
        this.companyTree.forEach((item) => {
          if (item.id === this.search.companyId) {
            this.projectTree = item.children
            if (this.projectTree.length > 0) {
              // this.search.projectId = this.projectTree[0].id
              this.getSectionByProjectId()
            }
          }
        })      } else {
        this.projectTree = []
        this.sectionTree = []
      }
    },

    /**
     * 根据项目id获取标段列表
     * getContractByProjectId
     * */
    getSectionByProjectId() {

      if (this.search.sectionId) {
        this.search.sectionId = ''
      }

      if (this.search.projectId) {
        this.projectTree.forEach((item) => {
          if (item.id === this.search.projectId) {
            this.sectionTree = item.children
            if (this.sectionTree.length > 0) {
              // this.search.sectionId = this.sectionTree[0].id
              this.getList(true)
            }
          }
        })
      } else {
        this.sectionTree = []
        this.search.sectinId = ''
        this.getList(true)
      }

    },
    showFiles(row, title) {
      console.log(row, '=============')
      this.fileTitle = title
      this.nowFileList = row.file

      if (this.nowFileList) {
        this.showFileDialog = true
      }
    },
    // 格式化表单数据
    formatter(row, column) {
      let array = column.property.split('.')
      let result
      array.forEach((item, i) => {
        result = result === undefined ? row[item] : result[item]
      })
      if (result === '' || result === undefined) {
        return '--'
      } else {
        // if(!isNaN(result)){
        //     return this.$publicJs.exchangeKuaiJi(result)
        // }
        return result
      }
    },
    // 获取合同列表 api
    getContractList(reload) {
      this.$httpGet(this.$store.state.httpHost.buss + '/japi/contract/getWorkContract',
      ).then(res => {
        if (res.data.status === 1) {
          if (res.data.data.length > 0) {

            this.workContractList = res.data.data;
            this.contractId = res.data.data[0].id
            this.contractId = res.data.data[0].id
            this.allowSelContract = true;
          } else {
            this.workContractList = null;
            this.contractId = null
          }

          res.data.data.forEach(item => {
            item.amount = this.$publicJs.exchangeKuaiJi(parseFloat(item.amount))
            this.fileOptions.push({
              label: item.number,
              value: item.id,
              amount: item.amount,
            });
          })

          if (this.fileOptions.length > 0) {
            this.selectFile = this.fileOptions[0].value
            // 获取标段下属
            this.seledContract(this.selectFile)
          }
        } else {
          this.$messageError(res.data.message)
        }
      }).catch(res => {
        console.log('请求出现错误', res);
        this.$messageError(this.$route.name + '请求失败')
      })
    },

    /**
     * 获取标段下属
     **/
    seledContract(val) {
      let obj = {};
      obj = this.fileOptions.find((item) => {
        return item.value === val;
      });
      this.priceAll = obj.amount
      this.contractId = obj.value
      this.contractNumber = obj.label
      this.getList()
    },

    //判断当前挂接数据是否已经发生变更且未生效
    getUUID(callback) {
      this.$httpPost(this.$store.state.httpHost.buss + "/japi/supervisorcontact/getUUID").then(res => {
        this.uuid = res.data.uuid
        if (callback) callback(res.data)
      }).catch(res => {
        console.log('请求出现错误', res);
        this.$messageError('detail提交详情请求失败')
      })
    },

    //获取专职安全员列表
    getConstrUserList(callback) {
      this.$httpPost(this.$store.state.httpHost.buss + "/japi/sgxslog/getConstrUserList?contractid=" + this.contractId).then(res => {

        console.log("获取专职安全员列表", res.data.data)
        res.data.data.forEach(item => {
          this.constrUser.push({
            label: item,
            value: item,
          });
        })
        //this.uuid = res.data.uuid
        if (callback) callback(res.data)
      }).catch(res => {
        console.log('请求出现错误', res);
        this.$messageError('detail提交详情请求失败')
      })
    },

    //#region 文件
    // 上传文件前
    beforeUpload(file) {
      if (file.size > 2000 * 1024 * 1024) {
        this.$messageError('上传文件大小不能超过500M')
      }
      console.log(file)
      let fd = new FormData()
      fd.append('file', file)
      this.$httpPost(`${this.$store.state.httpHost.file}/japi/filesystem/upload?maxFileSize=${file.size}&viewByAnon=true&longLife=false`,
        fd, {
        headers: {
          'Content-Type': 'multipart/form-data; boundary=----WebKitFormBoundaryIOi8qEBAFV1KN25n',
        }
      }).then(res => {
        if (res.data.status === 1) {
          this.file.push({
            name: file.name,
            size: file.size,
            url: res.data.link,
            id: res.data.id,
          })

          this.needuploadfile.push({
            name: file.name,
            size: file.size,
            url: res.data.link,
            id: res.data.id,
          })
          // 非新建时绑定文件
          if (this.detailType !== 'build') {
            this.bingFileForm([res.data.id], this.fileSystem.part[0])
          }
        } else {
          this.$messageError(res.data.message)
        }
      }).catch(res => {
        console.log('请求出现错误', res);
        this.$messageError(this.$route.name + '上传文件前-请求失败')
      })
    },

    removeFile(file, fileList) {
      console.log(file, fileList)
      this.unBingFile(file.id)
      this.file = fileList
    },
    // 查看文件
    checkFile(file) {
      this.$httpPost(
        this.$store.state.httpHost.file + `/japi/filesystem/getFilePreview?id=${file.id}&browserType=1`,
      ).then(res => {
        if (res.data.status === 1) {
          window.open(res.data.url)
        } else if (res.data.status === 0) {
          this.$messageError(res.data.message)
        } else {
          this.$messageError('在线预览失败 ')

        }                    // window.location.href = res.data.url
      }).catch(res => {
        console.log('请求出现错误', res);
        this.$toast('请求失败!')
      })

    },


    //预览
    viewFile(e) {
      this.loading = true
      this.$httpGet('/file-server/file/preview?id=' + e).then(response => {
        this.loading = false;
        //  如果是minio地址路径，则调用kkview
        if (!response.data.startsWith("/")) {
          window.open(PREVIEW_URL + '/onlinePreview?url=' + encodeURIComponent(Base64.encode(response.data)));
        } else {
          //  如果是转换后的previewGetFile，浏览器直接打开
          window.open(response.data);
        }
      }).catch(res => {
        console.log(res)
        this.loading = false;
      })

    },
    //下载文件
    dlFile(e) {
      this.$publicUpload.checkFile(e.id, e.fileName)
    },


    // 绑定文件到表单
    bingFileForm(fileIdsArray, part, callback) {
      if (this.detailType === 'update') {
        this.uuid = this.params.detailId
      }

      if (fileIdsArray.length === 0) return
      this.$httpPost(
        this.$store.state.httpHost.file + '/japi/filesystem/attachment/bindBigBatch',
        [{
          fileid: fileIdsArray, // 文件列表
          //form: this.detailId, // 表单
          form: this.uuid,
          sys: this.fileSystem.sys,
          module: this.fileSystem.module,
          part: part,
        }]
      ).then(res => {
        if (res.data.status === 1) {
          if (callback) callback()
        } else {
          this.$messageError(res.data.message)
        }
      }).catch(res => {
        console.log('请求出现错误', res);
        this.$toast('请求失败!')
      })
    },
    // 获取绑定的附件
    getFiles() {
      //console.log("获取绑定的附件---form",this.constrlogid)

      let loginMessage = this.$store.getters.getLoginMessage()
      this.$httpGet(
        `${this.$store.state.httpHost.file}/japi/filesystem/attachment/getFilesByAttach?sys=${this.fileSystem.sys}&module=${this.fileSystem.module}&form=${this.params.detailId}`,
      ).then(res => {
        if (res.data.status === 1) {
          this.fileSystem.attachId = res.data.attachid
          this.existsfile = []
          this.file = []
          if (res.data.attachinfos[0]) {

            let files = res.data.attachinfos[0].fileInfo
            console.log("获取绑定的附件", res)

            files.forEach(item => {
              this.file.push({
                name: item.name,
                size: item.size,
                link: item.link,
                id: item.id,
                url: this.$store.state.httpHost.file + item.link,
              })

            })
          }
        } else {
          this.$messageError(res.data.message)
        }
      }).catch(res => {
        console.log('请求出现错误', res);
        this.$messageError('请求失败!')
      })
    },
    // 解绑已绑定的文件
    unBingFile(fileId, callback) {
      this.$httpPost(
        `${this.$store.state.httpHost.file}/japi/filesystem/attachment/removeBindBatch?attachment=${this.fileSystem.attachId}&fileInfo=${fileId}`
      ).then(res => {
        if (callback) callback()
      }).catch(res => {
        console.log('请求出现错误', res);
        this.$messageError('请求失败!')
      })
    },

    // 获取列表 api
    getList(reload) {

      console.log(this.search.dateHandover)
      if (this.search.hasOwnProperty('dateHandover')) {
        if (this.search.dateHandover != null) {
          this.search.searchTime = this.search.dateHandover[0]
          this.search.searchTimes = this.search.dateHandover[1]
        } else {
          this.search.searchTime = null
          this.search.searchTimes = null
        }
      }

      if (reload) {
        this.search.pageNo = 0
      }
      this.list = []
      this.search.sortField = this.$sortName
      this.search.sortOrder = this.$sortType
      let data = JSON.parse(JSON.stringify(this.search))
      data.logDatesBegin = this.search.logDates ? this.search.logDates[0] : null
      data.logDatesEnd = this.search.logDates ? this.search.logDates[1] : null
      sgxslog.listPage(data).then(res => {
        if (res.code == 200) {
          if (res.data.content.length > 0) {
            this.list = res.data.content
          }
          this.search.pageSum = res.data.totalElements
        } else {
          msgUtil.error2(res.data.message)
        }
      })
    },
    // 切换列表
    paginationChange(index) {
      this.search.pageNo = index - 1
      this.getList()
    },
    // 显示详情弹窗 不同状态
    showDetailDialog(flag, params) {
      console.log(flag, params)
      if (!params) {
        params = {}
      }
      params.contractId = this.contractId;
      params.constrCompany = this.constrCompany;
      params.phaseId = this.measurePhaseNow.id
      params.log = this.measurePhaseNow.logList;
      params.contractNumber = this.contractNumber;
      params.constrCompanyName = this.constrCompanyName
      params.supervisorCompany = this.supervisorCompany
      params.supervisorCompanyName = this.supervisorCompanyName
      switch (flag) {
        case 'build':
          this.postDetailData = {
            show: true,
            type: 'build',
            typeName: '新增',
            params: params
          }
          break
        case 'update':
          this.postDetailData = {
            show: true,
            type: 'edit',
            typeName: '编辑',
            params: params
          }
          break
        case 'show':
          this.postDetailData = {
            show: true,
            type: 'check',
            typeName: '查看',
            params: params
          }
          break
        case 'history':
          this.postDetailData = {
            show: true,
            type: 'history',
            typeName: '历史',
            params: params
          }
          break
        case 'approve':
          this.postDetailData = {
            show: true,
            type: 'approve',
            typeName: '审批',
            params: params
          }
          break
      }
    },
    // 点击单元格 展示详情
    cellClick(row, column, cell, event) {
      // console.log(row, column, cell, event)
      console.log(column)
      if (column.property === 'logNumber') {
        this.postDetailData = {
          show: true,
          type: 'check',
          typeName: '查看',
          detailId: row.id,
        }
      }
    },
    handleSelectionChange(val) {
      this.selectedIds = []
      val.forEach(item => {
        this.selectedIds.push(item.id)
      })
    },
    // 事件处理的api请求
    sealDealHttp(url, query, param, callback) {
      this.$httpPost(
        this.$store.state.httpHost.buss + url + query,
        param
      ).then(res => {
        if (res.data.status === 1) {
          if (callback) callback(res.data)
          // 重新获取数据
          setTimeout(() => {
            this.getList(true)
          }, 1000)
        } else {
          this.$messageError(res.data.message)
        }
      }).catch(res => {
        console.log(res)
      })
    },


    // 事件处理的api请求
    sealDealHttps(url, query, param, callback) {
      this.$httpPost(
        this.$store.state.httpHost.buss + url + query,
        param
      ).then(res => {
        if (res.data.status === 1) {
          let data = res.data.data.entity
          this.$httpPost(

            this.$store.state.httpHost.file + `/japi/filesystem/getFilePreviewAfterDeal?&module=jlaqxslog&browserType=1`,
            [{
              data: data, // 文件列表
            }]

          ).then(res => {
            if (res.data.status === 1) {
              window.open(res.data.url)
            } else if (res.data.status === 0) {
              this.$messageError(res.data.message)
            } else {
              this.$messageError('在线预览失败 ')

            }                    // window.location.href = res.data.url
          }).catch(res => {
            console.log('请求出现错误', res);
            this.$toast('请求失败!')
          })

          if (callback) callback(res.data)
          // 重新获取数据
          setTimeout(() => {
            this.getList(true)
          }, 1000)
        } else {
          this.$messageError(res.data.message)
        }
      }).catch(res => {
        console.log(res)
      })
    },

    // 列表的操作流程
    handleClickDeal(res) {
      let type = res.type
      let detailId = res.detailId
      let url = res.url
      let name = res.name
      let actions = res.actions
      console.log(res)
      switch (type) {
        // 查看历史版本
        case 'getHistory':
          this.postHistoryData = {
            show: true,
            params: {
              url: res.url,
              formId: detailId
            }
          }
          break
        // 修改
        case 'update':
          // 显示详情弹窗
          this.showDetailDialog(type, {
            detailId: detailId,
            actions: actions
          })
          break
        // 查看
        case 'show':
          // 显示详情弹窗
          this.showDetailDialog(type, {
            detailId: detailId,
            actions: actions
          })
          break

        // 查看
        case 'download':
          // 显示详情弹窗
          this.sealDealHttps(url, `?id=${detailId}`, {}, () => {
            this.$messageSuccess('打开预览中!')
          })
          break

        // 上报、重新上报
        case 'report':
          this.$confirm('是否上报(重新上报)?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'info'
          }).then(() => {
            this.sealDealHttp(url, `?id=${detailId}`, () => {
              this.$messageSuccess('上报成功!')
            })
          }).catch(() => {
            console.log('请求出现错误');
          });
          break
        // 撤回上报
        case 'revokeReport':
          this.$prompt('撤回理由', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
          }).then(({ value }) => {
            if (value === null || value === '') {
              this.$messageError('请填写撤回理由后重试')
              return
            }
            this.sealDealHttp(url, `?id=${detailId}&description=${value}`, () => {
              this.$messageSuccess('撤回成功！')
            })
          }).catch(() => {
            console.log('请求出现错误');
          });
          break
        // 删除
        case 'delete':
          if (detailId === '') {
            this.$messageError('请先选择要删除的记录！')
            return
          }
          this.$confirm('确定是否删除？', '提示', {
            confirmButtonClass: 'iconfont icon-icon_ok',
            cancelButtonClass: 'iconfont icon-icon_cancel',
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'info'
          }).then(() => {
            this.sealDealHttp(url, ``, {
              idList: detailId.split(','),
            }, () => {
              this.$messageSuccess('删除成功!')
            })
          }).catch(() => {
            console.log('请求出现错误');
          });
          break



        // 同意
        case 'agree':
          this.$prompt('请输入同意审批意见', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
          }).then(({ value }) => {
            this.sealDealHttp(url, `?id=${detailId}&description=${value}`, () => {
              this.$messageSuccess('同意审批成功!')
            })
          }).catch(() => {
            console.log('请求出现错误');
          });
          break
        // 驳回
        case 'reject':
          this.$prompt('请输入驳回审批意见', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
          }).then(({ value }) => {
            this.sealDealHttp(url, `?id=${detailId}&description=${value}`, () => {
              this.$messageSuccess('驳回审批成功!')
            })
          }).catch(() => {
            console.log('请求出现错误');
          });
          break
      }
    },
    // 打开历史详情
    openHistoryDetail(res) {
      // 显示详情 并获取历史版本的详情
      this.showDetailDialog('history', {
        detailId: res.historyId,
        actions: {}
      })
    },
  },
}
</script>

<style scoped lang="scss">
.operate_wrap {
  height: 40px;
  width: 100%;
  box-sizing: border-box;
  .el-button,
  .el-select,
  .el-input {
    border-radius: 4px;
    font-family: PingFangSC-Medium;
    font-size: 14px;
    display: inline-block;
  }
  .el-date-editor--daterange {
    width: 300px;
  }
  .add {
    width: 88px;
  }
  .delete {
    width: 88px;
  }
  .search {
    width: 88px;
    float: right;
    color: #fff;
    margin-left: 10px;
  }
  .el-select {
    width: 140px;
    margin-left: 10px;
  }
  .input {
    width: 140px;
    float: right;
    margin-left: 10px;
    color: #3e556e;
  }
}
.flex {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}
.flex-center {
  display: flex;
  flex-direction: row;
  align-items: center;
}
.list_wrap {
  margin-top: 20px;
}
</style>
